#include "app_global.h"
// 
#include <string.h>
// 
#include "stm32f1xx.h"
// 
#include "flash_divide.h"
// app-store
#include "common_param.h"
// lib
#include "debug.h"

// 全局事件标志位
EventGroupHandle_t global_event;

//软件重启
void System_Reboot(softre_reason_t reason)
{
    // 关闭全局中断
    __disable_irq();
    // 记录重启信息到备份寄存器
    restart_info.softre_reason = reason;
    Restart_Info_Save_Bpr();
    // 重启
    NVIC_SystemReset();
}

//打印系统信息
void System_Info_Print(void)
{
    _DEBUG_PRINT(DBG_SYS, "\r\n");
    _DEBUG_PRINT(DBG_SYS, " _    _  ____ _____ _____  ______ \r\n");
    _DEBUG_PRINT(DBG_SYS, "| |  | |/ __ \\_   _|  __ \\|  ____|\r\n");
    _DEBUG_PRINT(DBG_SYS, "| |__| | |  | || | | |__) | |__   \r\n");
    _DEBUG_PRINT(DBG_SYS, "|  __  | |  | || | |  _  /|  __|  \r\n");
    _DEBUG_PRINT(DBG_SYS, "| |  | | |__| || |_| | \\ \\| |____ \r\n");
    _DEBUG_PRINT(DBG_SYS, "|_|  |_|\\____/_____|_|  \\_\\______|\r\n");
    _DEBUG_PRINT(DBG_SYS, "\r\n");
    _DEBUG_PRINTF(DBG_SYS, "firmware build time: %s %s\r\n", __DATE__, __TIME__);
    _DEBUG_PRINTF(DBG_SYS, "firmware name: %s\r\n", system_param.device_param.firmware_name);
    _DEBUG_PRINTF(DBG_SYS, "firmware boot version:[%s], app version:[%s]\r\n", 
                            system_param.device_param.firmware_boot_ver, 
                            system_param.device_param.firmware_app_ver);
    _DEBUG_PRINTF(DBG_SYS, "device id: %s\r\n", system_param.device_param.device_id);
    _DEBUG_PRINTF(DBG_SYS, "Restart type: %s\r\n", restart_type_table[restart_info.restart_type]);
    _DEBUG_PRINTF(DBG_SYS, "Softre restart reason: %s\r\n", softre_reason_table[restart_info.softre_reason]);
    _DEBUG_PRINTF(DBG_SYS, "sim iccid: %s\r\n", system_param.device_param.sim_iccid);
    _DEBUG_PRINTF(DBG_SYS, "\r\n");
}
